//
//  ZConsumerView.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/15.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZConsumerView.h"
@interface ZConsumerView (){
    UIImageView * _userImgaeView;// 头像
    UILabel * _userNameLabel;
    UILabel * _timeLabel;
}
@property (nonatomic,strong)LZUserInfo * userInfo;
@end
@implementation ZConsumerView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initlizeInterface];
    }
    return self;
}
- (void)setModel:(ZCVModel *)model {
    _model = model;
    NSURL * imageUrl = [NSURL URLWithString:_model.pic];
    [_userImgaeView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"icon_center_tx"]];
    _userNameLabel.text = model.name;
    _timeLabel.text = model.time;
}
- (void)initlizeInterface {
    _userInfo = [LZUserInfo getUserInfo];
    [self MakeSubView];
    [self addALLSubView];
    [self makeAllSubViewMasnoy];
}
- (void)MakeSubView {
    _userImgaeView = [[UIImageView alloc] init];
    _userImgaeView.layer.cornerRadius = 15*xsIZE;
    _userImgaeView.layer.masksToBounds = YES;
    [_userImgaeView sd_setImageWithURL:[NSURL URLWithString:_userInfo.userIcon] placeholderImage:[UIImage imageNamed:@"icon_center_tx"]];
    _userNameLabel = [[UILabel alloc] init];
    _userNameLabel.text = _userInfo.userName;
    _userNameLabel.textColor = KHGreenColor;
    _userNameLabel.font = [UIFont systemFontOfSize:13];
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.textColor = KHGaryColor;
    _timeLabel.font = [UIFont systemFontOfSize:11];
    _timeLabel.text = @"";
}
- (void)addALLSubView {
    [self addSubview:_userImgaeView];
    [self addSubview:_userNameLabel];
    [self addSubview:_timeLabel];
}
- (void)makeAllSubViewMasnoy {
    [_userImgaeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self).offset(13*xsIZE);
        make.width.height.offset(30*xsIZE);
    }];
    [_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(_userImgaeView.mas_right).offset(10*xsIZE);
        make.width.equalTo(self).multipliedBy(0.4);
        make.height.offset(13*xsIZE);
    }];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_userNameLabel.mas_bottom).offset(5*ysIZE);
        make.left.equalTo(_userNameLabel);
        make.width.equalTo(self).multipliedBy(0.6);
        make.height.offset(11*ysIZE);
    }];
    
}

- (void)setPersonInfoModel:(PersonInfoModel *)personInfoModel {
    _personInfoModel = personInfoModel;
    //时间
    NSString * str = personInfoModel.time;
    NSTimeInterval time = [str doubleValue];
    NSDate *detaildate = [NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    _timeLabel.text = currentDateStr;
    
    // 头像
    [_userImgaeView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", _personInfoModel.icon]] placeholderImage:[UIImage imageNamed:@"icon_center_tx"]];
    _userNameLabel.text = _personInfoModel.name;
}
@end
